<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/

if(isset($_SESSION['u_nic'])&&isset($_GET['id'])) {
	include('php/lib/panel_inc.php');
	$dom_current = intval($_GET['id']);
	$infos_dom = mysql_query("SELECT domaine,zone_dns,etat FROM comptes_domain WHERE id='".$dom_current."' AND u_nic='".$_SESSION['u_nic']."'");
	if(mysql_num_rows($infos_dom) == 1) {
		$infos_dom = mysql_fetch_array($infos_dom);
		if($infos_dom['etat'] == "1") {
			if(($_GET['valid'] == "1")) {
				query("DELETE FROM zones_dns_content WHERE id_zone = '".$id_zone['id']."'");
				query("DELETE FROM zones_dns WHERE id = '".$id_zone['id']."'");
				query("UPDATE comptes_domain SET zone_dns = '0' WHERE id = '$dom_current'");
				query("UPDATE comptes_domain SET dns1 = '". $bzh_config['ns_prim']."', dns2 = '".$bzh_config['ns_sec']."', dns3 = '', dns4 = '' WHERE id = '".intval($_GET['id'])."' AND u_nic = '".$_SESSION['u_nic']."'");
				$domaine = mysql_fetch_array(query("SELECT domaine FROM comptes_domain WHERE id = '".intval($_GET['id'])."' AND u_nic = '".$_SESSION['u_nic']."'"));
				$dom_ovh = $soap->domainInfo($soap_session, $domaine['domaine']);
				if(($dom_ovh->dns['0']->name != $bzh_config['ns_prim']) || ($dom_ovh->dns['1']->name != $bzh_config['ns_sec']) || ($dom_ovh->dns['2']->name != '') || ($dom_ovh->dns['3']->name != '')) {
					$soap->domainDnsUpdate($soap_session, $domaine['domaine'], $bzh_config['ns_prim'], '', $bzh_config['ns_sec'], '', '', '', '', '', '', '');
				}
				header("Location:domaine.html?id=".$dom_current);
			}
			else {
				$title = "Réinitialiser un domaine";
				$tplinc = "panel-domaine-reinit";
				$tpl->assign(array(
					'iconesleft' => 3,
					'prod' => '1',
					'prod_id' => intval($_GET['id'])
				));
				$dom_current = intval($_GET['id']);
				$infos_dom = mysql_query("SELECT domaine,zone_dns FROM comptes_domain WHERE id='".$dom_current."' AND u_nic='".$_SESSION['u_nic']."'");
				if(mysql_num_rows($infos_dom) == 1) {
					$infos_dom = mysql_fetch_array($infos_dom);
						$tpl->assign(array(
						"current_dom" => $infos_dom['domaine'],
						"zone_dns" => $infos_dom['zone_dns'],
						));
						$parse = 1;
				}
			}
		}
		else { header("Location:/panel/domaine.html?id=".intval($_GET['id'])); }
	}
}
else { header("Location:/site/connexion.html"); }
?>